<template>
  <div>
    <mt-header fixed title="道路货物运输量专项调查" style="z-index: 999999;">
      <span slot="left" @click="goBack">
        <mt-button icon="back" slot="left">返回</mt-button>
      </span>
      <!-- <mt-button v-if="reportedByOther=='1' || information=='业户'" icon slot="right" @click.native="insertDate">新增</mt-button> -->
      <mt-button  v-if="(reportedByOther==1&&information=='调查员'||reportedByOther==0&&information=='业户')" icon slot="right" @click.native="insertDate">新增</mt-button>
    </mt-header>
    <el-table border :data="tableData4" style="width: 100%" max-height="450">
      <el-table-column fixed prop="xh" label="序号" width="50" align="center"></el-table-column>
      <el-table-column prop="qtrllxmc" label="其他燃料类型名称" width="140" align="center"></el-table-column>
      <el-table-column prop="dycphm" label="对应车牌号码" width="120" align="center"></el-table-column>
      <el-table-column prop="dycpys" label="对应车牌颜色" width="120" align="center"></el-table-column>
      <el-table-column label="操作" width="120" align="center">
        <template slot-scope="scope"> 
          <el-button
            v-if="(reportedByOther==1&&information=='调查员'||reportedByOther==0&&information=='业户')"
            @click.native.prevent="deleteRow(scope.$index, tableData4)"
            type="text"
            size="small"
          >移除</el-button>
          <el-button v-if="(reportedByOther==1&&information=='调查员'||reportedByOther==0&&information=='业户')" @click.native.prevent="updateRow(scope.$index)" type="text" size="small">修改</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
      
      <script>
      import {Toast} from 'mint-ui'
export default {
  data() {
    return {
      tableData4: [
        {
          recid: "",
          floatorder: "",
          xh: "1",
          qtrllxmc: "",
          dycphm: "",
          dycpys: "",
        }
      ],
      // 根据公司状态判定新增按钮是否显示 add by qzn 20190625
      reportedByOther: this.$route.query.reportedByOther,
      information: this.$route.query.information,
    };
  },
  watch: {},
  mounted() {
    this.getCode();
  },
  methods: {
    //点击后退
    goBack() {
      this.$router.go(-1);
    },
    //查询
    getCode() {
      let data = {};
      data.yhmlkRecid = this.$route.query.yhmlk;
      this.axios
        .post(
          "http://zxdc.catsic.com:9090/sampling/assit/findFzdcbfd07",
          { data: data },
          {
            headers: {
              "Content-Type": "application/json",
              mobileHeader:
                '{"sessionId":' + localStorage.getItem("sessionId") + "}"
            }
          }
        )
        .then(
          result => {
             console.log("辅助5 其他-查询返回："+JSON.stringify(result))
            if (result.data.status == "1000") {
                this.tableData4.splice(0);
                if( result.data.data.MSG != "没有查询到结果"){
                    let i = 1;
                    result.data.data.Fzdcbfd07.forEach(item => {
                        let tableData = {};
                        tableData.recid = item.recid;
                        console.log("item.recid"+item.recid);
                        tableData.floatorder = item.floatorder;
                        tableData.xh = i++;
                        (tableData.qtrllxmc = item.fzdcbfd72019001),
                        (tableData.dycphm = item.fzdcbfd72019002),
                        (tableData.dycpys = this.getCarColorName(item.fzdcbfd72019003)),
                        this.tableData4.push(tableData);
                    });
                }
            } else {
                Toast(result.data.data.MSG);
            }
          },
          error => {
            console.log("getyhcars request error:" + error);
          }
        );
      //console.log(this.$route.query.yhmlk);
    },
    //新增
    insertDate() {
      this.$router.push({
        path: "/home/auxiliaryTableFiveOtherInsert/:yhmlk",
        query: { yhmlk: this.$route.query.yhmlk }
      });
    },
    //删除
    deleteRow(index) {
      let data = {};
      data.recid = this.tableData4[index].recid;
      console.log(JSON.stringify(data));
      this.axios
        .post(
          "http://zxdc.catsic.com:9090/sampling/assit/deleteFzdcbfd07",
          { data: data },
          {
            headers: {
              "Content-Type": "application/json",
              mobileHeader:
                '{"sessionId":' + localStorage.getItem("sessionId") + "}"
            }
          }
        )
        .then(
          result => {
              console.log("删除返回-----"+JSON.stringify(result));
            if (result.data.status == "1000") {
              this.getCode();
              
            }else{
                Toast(result.data.msg);
            }
          },
          error => {
            console.log("getyhcars request error:" + error);
          }
        );
      //console.log(index, this.tableData4[index]);
      this.getCode();
    },
    //修改
    updateRow(index) {
      this.$router.push({
        path: "/home/auxiliaryTableFiveOtherUpdate/:yhmlk/:recid/:floatorder",
        query: {
          yhmlk: this.$route.query.yhmlk,
          recid: this.tableData4[index].recid,
          floatorder: this.tableData4[index].floatorder
        }
      });
      console.log(index, this.tableData4[index]);
    },
    // 获取车牌颜色名称
                getCarColorName(code) {
                  var goodsTypes = [
                    {
                      code: "1",
                      name: "蓝色"
                    },
                    {
                      code: "2",
                      name: "黄色"
                    },
                    {
                      code: "3",
                      name: "黑色"
                    },
                    {
                      code: "4",
                      name: "白色"
                    },
                    {
                      code: "5",
                      name: "黄绿"
                    },
                    {
                      code: "6",
                      name: "渐变绿"
                    },
                    {
                      code: "9",
                      name: "其他"
                    }
                  ];
                  var name;
                  goodsTypes.forEach(item => {
                    if (item.code === code) {
                      name = item.name;
                    }
                  });
                  return name;
              },
  }
};
</script>